import { createRouter, createWebHistory } from "vue-router";
import exampleRouters from './exampleRouters'
import mainoutRouters from './mainoutRouters'
import useLayoutBreadcrumb from '@/layout/useLayoutBreadcrumb'
const {
  pageTitle,setPageTitle
} = useLayoutBreadcrumb();



const router = createRouter({
  history: createWebHistory(),
  routes: [],
});



router.addRoute({
  name: "root",
  path: "/",
  redirect: "/index",
})

router.addRoute({
  path: "/index",
  component: () => import("@/views/index.vue"),
})


router.addRoute("root", exampleRouters)

mainoutRouters.forEach( item=>{
  router.addRoute(item)
})

/**
 * 路由守卫
 */
router.beforeEach((to, from,next) => {
  // console.log(from,to)
  next();
})


router.afterEach((to, from) => {
  console.log(from,to)

  router.getRoutes(to.name);
  // 设置面包屑内容
  setPageTitle(to.meta.title)
})

export default router;